// ---------------------------------------------------------------------------

#pragma hdrstop

#include "ModuleInfo.h"

// ---------------------------------------------------------------------------

#pragma package(smart_init)

TModuleInfo __fastcall TModuleInfo::GetModuleInfo(Classes::TComponent* AOwner, int id) {

    TModuleInfo module;
    module.Id = 0;
    TXMLDocument *doc = new TXMLDocument(AOwner);
    try {
	doc->LoadFromXML(TGlobalVariable::UserInfo.UserModule);
	_di_IXMLDOMNodeRef refNode = doc->DocumentElement->DOMNode;
	_di_IXMLDOMNode root = refNode->GetXMLDOMNode();
	_di_IXMLDOMNode node;
	_di_IXMLDOMNode attr;
	if (!root->selectSingleNode("//ROWDATA/ROW[@id=\"" + IntToStr(id) + "\"]", node)) {
	    module.Id = id;
	    node->attributes->getNamedItem("name", attr);
	    module.Name = attr->text;
	    node->attributes->getNamedItem("level", attr);
	    module.Level = StrToInt(attr->text);
	    node->attributes->getNamedItem("parent_id", attr);
	    module.ParentId = StrToInt(attr->text);
	    node->attributes->getNamedItem("code", attr);
	    module.Code = attr->text;
	    node->attributes->getNamedItem("conf", attr);
	    try {
		module.Conf = DecodeString(attr->text);
	    }
	    catch(...) {
		module.Conf = "";
	    }
	    node->attributes->getNamedItem("type", attr);
	    module.ModuleType = StrToInt(attr->text);
	    node->attributes->getNamedItem("remarks", attr);
	    module.Remarks = attr->text;
	    module.ModuleConf = TModuleConf::GetModuleConfig(AOwner, module.Conf);
	}
    }
    __finally {
	delete doc;
    }
    return module;
}
